package com.ruoyi.common.runner;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringBootVersion;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @author wq
 * @date 2022/7/23 9:56
 */
@Slf4j
@Component
public class FastApplication implements CommandLineRunner {
    @Resource
    private Environment env;

    @Override
    public void run(String... args) {
        log.debug("Let's inspect the beans provided by Spring Boot:");
        String version = SpringBootVersion.getVersion();
        log.info(String.format("\n----------------------------------------------------------\n\t" +
                                       "Application '%s' is running at '%s'! \n\t" +
                                       "The project Access URL: http://localhost:%s\n\t" +
                                       "The following profiles are active: %s\n" +
                                       "\tThe project springboot version: %s\n" +
                                       "----------------------------------------------------------",
                               env.getProperty("spring.application.name"),
                               (LocalDateTime.now()),
                               env.getProperty("server.port"),
                               env.getProperty("spring.profiles.active"), version));
    }
}
